package cn.hello

/**
  * Created by lzd on 2018/8/10.
  */
object Hello {
  def main(args: Array[String]): Unit = {
    val a = 1
    var b = 2
    var c: String = "hello"
    println(a)
    println(b)
    println(c)
  }
}

object Hello2 {
  def main(args: Array[String]): Unit = {
    val x = 1;
    val y = if (x > 1) 2 else 0
    val z = if (x == 1) "ok" else 0
    val c = if (x > 1) 2
    println(z)
    println(c)
    println(y)

    val zz = if (x != 1) "lala"
    else if (x == 1) "ok"

    println(zz)

    val res = {
      if (x == 0) "==0"
      else if (x == 1) "==1"
      else "==没有"
    }

    println(res)
  }
}

object Hello3 {
  def main(args: Array[String]): Unit = {
    for (x <- 1 to 10) {
      print(x)
    }
    println("=============================")
    var arr = Array(1, 2, 3, 4, 5)
    for (x <- arr) {
      print(x)
    }
    println ("================")
    //类似双重循环
    for(i <- 1 to 3; j <- 1 to 3 if i != j)
      print ((10 * i + j) + " ")
    println ()
    println ("================")
    //加了yield将结果放到集合中
    val v =  for (i <- 1 to 10)  yield i * 10
    println (v)

  }
}
